<?php
require_once ('config.php');

$create_DB_sql = "CREATE DATABASE if NOT EXISTS " . DB_NAME. " CHARACTER SET utf8 COLLATE utf8_general_ci";
$create_table_user = "CREATE TABLE IF NOT EXISTS " . TAB_USER . " (
  ID MEDIUMINT NOT NULL AUTO_INCREMENT,
  userid VARCHAR(32) NOT NULL,
  gcmid VARCHAR(250) NOT NULL,
  password VARCHAR(32) NOT NULL,
  reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY(ID),
  UNIQUE (userid),
  UNIQUE (gcmid),
  INDEX(userid)
)";

$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con) {
	die('Could not connect: ' . mysql_error());
}

if (!mysql_query($create_DB_sql, $con)) {
	die("Error creating database: " . mysql_error());
}

mysql_select_db(DB_NAME, $con);
if (!mysql_query($create_table_user, $con)) {
	die("Error creating table: " . mysql_error());
}

mysql_close($con);

echo ('init ok.');
?>